﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using Model;

namespace DAL
{
    public class D_JobIntention : IJobIntention
    {
        WishDayEntities _e;
        public D_JobIntention()
        {
            _e = new WishDayEntities();
        }

        public void Add(JobIntention obj)
        {
            _e.JobIntention.Add(obj);
            _e.SaveChanges();
        }

        public void Delete(int id)
        {
            _e.JobIntention.Remove(_e.JobIntention.Find(id));
            _e.SaveChanges();
        }

        public JobIntention FindById(int id)
        {
            return _e.JobIntention.Find(id);
        }

        public Param_JobIntention FindByTemplateID(int id)
        {
            var data = from j in _e.JobIntention.AsEnumerable()
                       where j.TemplateID == id
                       select new Param_JobIntention
                       {
                           JobID = j.JobID,
                           JobName = j.JobName,
                           JobCity = j.JobCity,
                           JobSalary = j.JobSalary,
                           EntryTime = j.EntryTime,
                           TemplateID = j.TemplateID,
                       };
            return data.FirstOrDefault();
        }

        public List<JobIntention> GetAll()
        {
            return _e.JobIntention.ToList();
        }

        public void Update(int id, JobIntention obj)
        {
            var data = _e.JobIntention.Find(id);
            data.JobName = obj.JobName;
            data.JobCity = obj.JobCity;
            data.JobSalary = obj.JobSalary;
            data.EntryTime = obj.EntryTime;
            data.Template = obj.Template;
            _e.SaveChanges();
        }
    }
}
